import { createRouter, createWebHistory } from "vue-router";

const routes = [
  {
    path: "/",
    name: "home",
    component: () => import("../views/x-home.vue"),
  },
  {
    path: "/error",
    name: "error",
    component: () => import("../views/x-error.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

router.beforeEach((to, from) => {
  if (!routes.find((it) => it.path === to.path)) {
    return "/error";
  }
});

export default router;
